package com.example.personalcenter;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashSet;
import java.util.Set;

public class SharedPrefUtil {
    private static final String PREF = "user_pref";
    private static final String KEY_INTERESTS = "interests";

    public static void saveInterests(Context ctx, Set<String> interests) {
        ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE)
                .edit()
                .putStringSet(KEY_INTERESTS, interests)
                .apply();
    }

    public static Set<String> getInterests(Context ctx) {
        return ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE)
                .getStringSet(KEY_INTERESTS, new HashSet<>());
    }

    public static void clear(Context ctx) {
        ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE)
                .edit()
                .clear()
                .apply();
    }
}